﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO.Common;
using DTO.Common;
using System.Data;
using System.Data.Common;

namespace DAO.Stores
{
    public static class Extensions
    {
        public static List<ParameterHelper> ToParameterList(this Product product)
        {
            return new List<ParameterHelper> { 
                new ParameterHelper { DbType = DbType.Int32, Name = "productCode", Value = product.Code },
                new ParameterHelper { DbType = DbType.String, Name = "designation", Value = product.Designation },
                new ParameterHelper { DbType = DbType.Decimal, Name = "price", Value = product.Price },
                new ParameterHelper { DbType = DbType.Int32, Name = "stock", Value = product.Stock },
                new ParameterHelper { DbType = DbType.String, Name = "type", Value = product.Type }
            };
        }

        public static void FromDataReader(this Product product, DbDataReader reader)
        {
            //code, stock, type, designation, price
            product.Code        = reader.GetInt32(0);
            product.Stock       = reader.GetInt32(1);
            product.Type        = (ProductType)Enum.Parse(typeof(ProductType), reader.GetString(2));
            product.Designation = reader.GetString(3);
            product.Price       = reader.GetDecimal(4);
        }

    }
}
